import React from 'react'
import styles from './Login.module.scss'
import {Button, message} from 'antd'
import { useSelector } from 'react-redux/es/exports'
import { useAppDispatch } from '../../store'
import type { RootState } from '../../store'
import { loginAction, updateToken } from '../../store/modules/my'


export default function Login() {
    const token = useSelector((state: RootState) => state.my.token)
    const dispatch = useAppDispatch()
    const handleLogin = () => {
        dispatch(loginAction({email: '1111@qq.com',password:12313})).then((action)=>{
            const {errcode, token} = (action.payload as {[index: string]: unknown}).data as {[index: string]: unknown}
            if ( errcode === 0 && typeof token === 'string' ){
                dispatch(updateToken(token))
                message.success('登录成功')
            }
            else {
                message.error('登录失败')
            }
        })
    }
  return (
    <div>Login
        <Button onClick={handleLogin}></Button>
    </div>
  )
}
